package control;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/shop/addList")
public class AddList extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //req.setCharacterEncoding("utf-8");
        String[] goods=req.getParameterValues("fz");
        for (String s:goods){
            System.out.println(s+"  ");
        }
        HttpSession session=req.getSession();
        List<String> listGoods=(List<String>) session.getAttribute("goods");
        if (listGoods==null){
            listGoods=new ArrayList<>();
            session.setAttribute("goods",listGoods);
        }
        for (String s:goods){
            listGoods.add(s);
        }
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charst=utf-8");
        PrintWriter out=resp.getWriter();
        out.write("{\"status\":\"添加成功!\"}");
        out.close();
    }
}
